﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace HighFantasy
{
    public enum ObjectType
    {
        Tree = 1,

        Brush = 2
    
    
    
    
    }

    public class Object
    {
        private Texture2D Rectangular;
        private Animation Texture;
        private AnimationPlayer sprite;
        private SpriteEffects flip;
        private ObjectType Objtype;
        public string Name;

        public Level Level
        {
            get { return level; }
        }
        Level level;

        public int X, Y, Width, Height, left, top;

        // Physics state
        public Vector2 Position
        {
            get { return position; }
            set { position = value; }
        }
        Vector2 position;

        public Vector2 Velocity
        {
            get { return velocity; }
            set { velocity = value; }
        }
        Vector2 velocity;

        public Rectangle localBounds;

        public Rectangle BoundingRectangle
        {
            get
            {
                int left = (int)Math.Round(Position.X - sprite.Origin.X) + localBounds.X;
                int top = (int)Math.Round(Position.Y - sprite.Origin.Y) + localBounds.Y;

                return new Rectangle(left, top, localBounds.Width, localBounds.Height);
            }
        }

        public Object(string name, Level level, int X, int Y, int Width, int Height, ObjectType type)
        {
            this.Name = name;
            this.level = level;
            this.X = X * 32;
            this.Y = Y * 32;
            this.Width = Width;
            this.Height = Height;
            this.Objtype = type;
            left = Width / 2;
            top = Height;
            localBounds = new Rectangle(X * 32 + left, Y * 32 + top, Width, Height);
            Position = new Vector2(this.X, this.Y);

            LoadContent();

        }

        public void LoadContent()
        {

            switch (Objtype){

                case ObjectType.Tree:

                Texture = new Animation(Level.Content.Load<Texture2D>("Sprites/Nature/Tree_1"), 0.5f, true, 1);
                Rectangular = Level.Content.Load<Texture2D>("Background/Player_rect");
                break;


                case ObjectType.Brush:

                Rectangular = Level.Content.Load<Texture2D>("Background/Player_rect");
                Texture = new Animation(Level.Content.Load<Texture2D>("Sprites/Nature/Brush"), 0.5f, true, 1);
                break;

                 }
            
            
          
            


            sprite.PlayAnimation(Texture);
        }

        public void Update(GameTime gameTime)
        {


        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            // Flip the sprite to face the way we are moving.
            if (Velocity.X > 0)
                flip = SpriteEffects.None;


            // Draw that sprite.
            sprite.Draw(gameTime, spriteBatch, Position, flip);
            spriteBatch.Draw(Rectangular, localBounds, Color.White);
        }
    }
}
